﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using WinnerCMS.Data;
using WinnerCMS.Model;
using WinnerCMS.Common;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 WinnerCMS_GoodsCustomFieldValues 的摘要说明。
    /// </summary>
    public class GoodsCustomFieldValuesManage
    {
        private static readonly GoodsCustomFieldValuesDal MyDAL = new GoodsCustomFieldValuesDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="goodsId"></param>
        /// <param name="fields"></param>
        /// <param name="values"></param>
        public Result Add(int goodsId, IList<string> fields, IList<object> values)
        {
            Result resu = new Result();
            for (int i = 0; i < fields.Count; i++)
            {
                GoodsCustomFieldValue model = new GoodsCustomFieldValue
                {
                    EnableSearch = true,
                    GoodsId = goodsId,
                    FieldName = fields[i],
                    FieldValue = values[i].ToString()
                };

                if (model.FieldName.Length == 0)
                {
                    resu.Errors = "“字段”不能为空！";
                    return resu;
                }

                MyDAL.Add(model);
            }

            return resu;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="goodsId"></param>
        /// <param name="fields"></param>
        /// <param name="values"></param>
        public Result Edit(int goodsId, IList<string> fields, IList<object> values)
        {
            Result resu = new Result();
            for (int i = 0; i < fields.Count; i++)
            {
                GoodsCustomFieldValue model = new GoodsCustomFieldValue
                {
                    EnableSearch = true,
                    GoodsId = goodsId,
                    FieldName = fields[i],
                    FieldValue = values[i].ToString()
                };

                if (model.FieldName.Length == 0)
                {
                    resu.Errors = "“字段”不能为空！";
                    return resu;
                }

                MyDAL.Edit(model);
            }
            return resu;
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="IDs"></param>
        /// <returns></returns>
        public Result Delete(string IDs)
        {
            Result res = new Result();
            if (string.IsNullOrEmpty(IDs))
            {
                res.Errors = "至少选择一项。";
            }
            else
            {
                MyDAL.Delete(MyConvert.ConvertToArr(IDs));
            }
            return res;
        }

        #endregion

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        public GoodsCustomFieldValue GetInfo(int ID)
        {
            return MyDAL.GetInfo(ID);
        }

        #endregion
    }
}